/*
 * @Author: 谢小康 2170673706@qq.com
 * @Date: 2023-11-21 18:10:54
 * @LastEditors: 谢小康 2170673706@qq.com
 * @LastEditTime: 2023-12-17 12:39:41
 * @FilePath: \My-bolg\server\model\article.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

const { DataTypes } = require('sequelize');
const sq = require('./db.js') 
const moment= require('moment') 
const article = sq.define('article', {
    article_title:{
        type: DataTypes.STRING,
        require: true,
        comment: "文章名称",
    },
    article_author:{
        type: DataTypes.STRING,
        require: true,
        defaultValue: "",
        comment: "文章作者",
    },
    article_content:{
        type:DataTypes.TEXT,
        require: true,
        comment: "博客的文章内容",
    },
    article_cover:{
        type:DataTypes.STRING,
        require: false,
        defaultValue: "",
        comment: "博客封面地址",
    },
    article_description:{
        type:DataTypes.STRING,
        require: true,
        defaultValue: "",
        comment: "博客描述",
    },
    article_istop:{
        type:DataTypes.BOOLEAN,
        require: true,
        defaultValue: false,
        comment: "博客是否是置顶",
    },
    articlee_strs:{
        type:DataTypes.INTEGER,
        require: true,
        defaultValue: 0,
        comment: "博客点赞量",
    },
    article_viewtime:{
        type:DataTypes.INTEGER,
        require: true,
        defaultValue: 0,
        comment: "博客浏览量",
    },
    article_status:{
        type: DataTypes.INTEGER,
        require: true,
        defaultValue: 1,
        comment: "文章状态  1 公开 2 草稿箱",
      },
      createdAt: {
        type: DataTypes.DATE,
        get() {
          return moment(this.getDataValue("createdAt")).format("YYYY-MM-DD HH:mm:ss")
        },
      },
      updatedAt: {
        type: DataTypes.DATE,
        get() {
          return moment(this.getDataValue("updatedAt")).format("YYYY-MM-DD HH:mm:ss")
        },
      },
}, {
  // 这是其他模型参数
  freezeTableName: true,
});
/* article.sync({ force: true }) */
module.exports = article;